957. Prison Cells After N Days - LeetCode Solution


Hash

Python Code:

class Solution:
    def prisonAfterNDays(self, cell: List[int], n: int) -> List[int]:

        l = []

        count =0

        for i in range(n):

            r = []
            r.append(0)

            for j in range(1, len(cell) - 1, 1):
                if cell[j - 1] == cell[j + 1]:
                    r.append(1)

                else:
                    r.append(0)

            r.append(0)

            cell = r

            l.append(cell)

            if l[0] == cell and count!= 0:
                l.pop()
                break
            count=1




        return l[n%len(l) -1]


Comments

Submit
0 Comments
More Questions

1485A - Add and Divide
337B - Routine Problem
1392D - Omkar and Bed Wars
76E - Points
762C - Two strings
802M - April Fools' Problem (easy)
577B - Modulo Sum
1555B - Two Tables
1686A - Everything Everywhere All But One
1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height
1506C - Double-ended Strings
340A - The Wall
377A - Maze
500A - New Year Transportation
908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite